home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / FixMFMDevice.lha / Source / ReadFile.s < prev    next >
Encoding:
Text File  |  1996-09-21  |  1.2 KB  |  61 lines

  1. ;*-----------------------------------------------------------------------*
  2. ;* ReadFile 1.1        © Dave Jones 1993                 *
  3. ;* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                 *
  4. ;* Returns    :- d0 = File Length (0=ok -2 if no mem, -1 if empty file)*
  5. ;*           a0 = Ptr to file buffer                 *
  6. ;*-----------------------------------------------------------------------*
  7.  
  8. ReadFile    Move.l    _Dosbase(a5),a6
  9.         Lea    PathnameBuffer(PC),a0
  10.         Move.l    a0,d1
  11.         Move.l    #1005,d2
  12.         Call    Open
  13.         Tst.b    d0
  14.         Beq.b    .Error
  15.         Move.l    d0,d7
  16.  
  17.         Move.l    d7,d1
  18.         Moveq.l    #0,d2
  19.         Moveq.l    #1,d3        ; Seek to end of file.
  20.         Call    Seek
  21.  
  22.         Move.l    d7,d1
  23.         Moveq.l    #0,d2
  24.         Moveq.l    #-1,d3
  25.         Call    Seek        ; Seek to start. (Returns old pos)
  26.         Move.l    d0,LoadFileSize(a5)
  27.         Move.l    d0,LoadBufferSize(a5)
  28.         Beq.b    .EmptyFile
  29.  
  30.  
  31.         Moveq.l    #1,d1            ; Memf_public
  32.         Move.l    4.w,a6
  33.         Call    AllocMem
  34.         Tst.l    d0
  35.         Beq.b    .Nomemory
  36.         Move.l    d0,LoadAddr(a5)
  37.  
  38.         Move.l    d7,d1
  39.         Move.l    LoadAddr(a5),d2
  40.         Move.l    LoadFileSize(a5),d3
  41.         Move.l    _Dosbase(a5),a6
  42.         Call    Read
  43.  
  44.         Move.l    d7,d1
  45.         Call    Close            ; Close input file.
  46.         Moveq.l    #0,d0
  47.         Rts
  48.  
  49.  
  50. .NoMemory    Move.l    d7,d1
  51.         Call    Close
  52.         ;Print    NoMemToLoadFileTxt
  53.         Moveq.l    #-2,d0
  54.         Rts
  55.  
  56. .EmptyFile    Move.l    d7,d1
  57.         Call    Close
  58.         ;Print    EmptyFileTxt
  59. .Error        Moveq.l    #-1,d0
  60.         Rts
  61.